from django_celery_beat.models import CrontabSchedule
from rest_framework import viewsets
from rest_framework.response import Response

from apps.CeleryTimedTask.serializers import CrontabScheduleSerializers


class CrontabViewSet(viewsets.ModelViewSet):
    queryset = CrontabSchedule.objects.all()
    serializer_class = CrontabScheduleSerializers
    ordering = ['id']


    def create(self, request, *args, **kwargs):
        res = super().create(request, *args, **kwargs)
        return Response({
            "code": 200,
            "data": {"data": res.data},
            "message": "OK",
        })

    def retrieve(self, request, *args, **kwargs):
        res = super().retrieve(request, *args, **kwargs)
        return Response({
            "code": 200,
            "data": {"data": res.data},
            "message": "OK",
        })

    def update(self, request, *args, **kwargs):
        res = super().update(request, *args, **kwargs)
        return Response({
            "code": 200,
            "data": {"data": res.data},
            "message": "OK",
        })